package com.pan.cuiniubi.entity;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

@Data
@NoArgsConstructor
@AllArgsConstructor
@Accessors(chain = true)
public class MethodInfo {
    String methodName;
//    Class returnType;

    String returnStr;
    List<Member> parameterList;

    public String getMethodLineStr(){
        String argsStr = parameterList.stream()
                .map(p->p.getMemberType().getName()+" "+p.getMemberName())
                        .reduce((x,y)->x+", "+y).get();
        String result = "\t"+returnStr+" "+methodName+"("+argsStr+");\n";
        return result;
    }

    public MethodInfo setParameterList(Member member){
        List<Member> list = new ArrayList<>();
        list.add(member);
        parameterList = list;
        return this;
    }
    public MethodInfo setParameterList(Member member,Member... members){
        List<Member> list = new ArrayList<>();
        list.add(member);
        list.addAll(Arrays.asList(members));
        parameterList = list;
        return this;
    }
}
